#version 330 core
out vec4 FragColor;

in vec3 Normal;
in vec3 FragPos;

uniform vec3 lightPos;      //灯光位置
uniform vec3 viewPos;       //视线位置
uniform vec3 lightColor;    //灯光颜色
uniform vec3 objectColor;   //物体位置

void main()
{
    // ambient
    float ambientStrength = 0.1;                                //环境光强度
    vec3  ambient = ambientStrength * lightColor;               //计算后的环境光颜色

    // diffuse
    vec3  norm = normalize(Normal);
    vec3  lightDir = normalize(lightPos - FragPos);             //漫反射方向
    float diff = max(dot(norm, lightDir), 0.0);                 //漫反射强度
    vec3  diffuse = diff * lightColor;                          //计算后的漫反射灯光颜色

    // specular
    float specularStrength = 0.8;                                 //镜面反色强度强度
    vec3  viewDir = normalize(viewPos - FragPos);               //视线方向
    vec3  reflectDir = reflect(lightDir, norm);                 //反射光方向
    float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);   //镜面反射强度(这个32是高光的反光度(Shininess))
    vec3  specular = specularStrength * spec * lightColor;      //计算后的镜面反色颜色

    vec3 result = (ambient + diffuse + specular) * objectColor; //计算后的物体实际颜色
    FragColor = vec4(result, 1.0);
}